package xml.ex.student.service;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Element;

import xml.ex.student.entity.StudentEntity;

public class StudentService {
	
	/**
	 * 初始化xml
	 * @return
	 */
	public List<StudentEntity> getAllStudent(){
		List<StudentEntity> list=new ArrayList<StudentEntity>();
		
		StudentEntity s1 = new StudentEntity();
		s1.setId(1);
		s1.setName("刘浩");
		s1.setAge(23);
		s1.setMajor("全能");
		StudentEntity s2 = new StudentEntity();
		s2.setId(1);
		s2.setName("刘浩2");
		s2.setAge(23);
		s2.setMajor("全能");
		StudentEntity s3 = new StudentEntity();
		s3.setId(1);
		s3.setName("刘浩3");
		s3.setAge(23);
		s3.setMajor("全能");
		StudentEntity s4 = new StudentEntity();
		s4.setId(1);
		s4.setName("刘浩4");
		s4.setAge(23);
		s4.setMajor("全能");
		
		list.add(s4);
		list.add(s3);
		list.add(s2);
		list.add(s1);
		
		return list;
	}
	
	/**
	 * 添加一个节点
	 * @param student
	 * @param root
	 */
	public void insertNode(StudentEntity student,Element root){
		Element stu = root.addElement("student");
		stu.addAttribute("id", ""+student.getId());
		Element elementname = stu.addElement("name");
		elementname.setText(student.getName());
		Element ageElement = stu.addElement("age");
		ageElement.setText(""+student.getAge());
		Element majorElement = stu.addElement("major");
		majorElement.setText(student.getMajor());
		
		
	}

}
